cd "C:\Users\David\Dropbox\My Work Documents\Volatility and Partisan Bias - Kate Hansen\Replication Archive\tables"
set more 1

use "..\studies_1_2.dta", clear

***SUMMARY STATS
estpost summarize female r_white r_black r_hispanic r_other age educ income_nomiss incomemis democrat republican partyid  if study_1==1
eststo study_1, title("Study 1 (DOW)")
estpost summarize female r_white r_black r_hispanic r_other age educ income_nomiss incomemis democrat republican partyid  if study_1==0
eststo study_2, title("Study 2 (DOW)")

**center objective measure so 0 = actual change
gen obj_centered=object-3803.02 if trump==0
replace obj_centered=object-4879.10 if trump==1
label var obj_centered "Perceived Objective Change (centered)"


//Create measure excluding responses that indicate the DOW either decreased over the period or increased by more than 10,000
recode objective (-10000/-1 10001/300000=.), gen(trim_obj_raw)
gen trim_obj=trim_obj_raw-3803.02 if trump==0
replace trim_obj=trim_obj_raw-4879.10 if trump==1
label var trim_obj "Perceived Objective Change (centered)"
recode study_1 (1=0) (0=1), gen(study_2)
recode named (1=0) (0=1), gen(unnamed)

//Regression models for estimates reported in figures
foreach i in subjective obj_centered trim_obj{
forvalues s=1/2{ 
reg `i' party_congruence##named trump if study_`s'==1,r
lincomest 1.party_congruence 
est store `i'_nname_s`s'

reg `i' party_congruence##unnamed trump if study_`s'==1,r
lincomest 1.party_congruence 
est store `i'_name_s`s'

reg `i' party_congruence##named trump if low_v==1 & study_`s'==1,r
lincomest 1.party_congruence 
est store `i'_nname_lv_s`s'

reg `i' party_congruence##named trump if high_v==1 & study_`s'==1,r
lincomest 1.party_congruence 
est store `i'_nname_hv_s`s'

reg `i' party_congruence##unnamed trump if low_v==1 & study_`s'==1,r
lincomest 1.party_congruence 
est store `i'_name_lv_s`s'

reg `i' party_congruence##unnamed trump if high_v==1 & study_`s'==1,r
lincomest 1.party_congruence 
est store `i'_name_hv_s`s'
}
}

***TESTS of Significance of party congruence by condition and study
reg subjective party_congruence##named trump if study_1==1, r
lincom 1.party_congruence#1.named+ 1.party_congruence
reg subjective party_congruence##named trump if study_2==1, r
lincom 1.party_congruence#1.named+ 1.party_congruence

reg obj_centered party_congruence##named trump if study_1==1, r
lincom 1.party_congruence#1.named+ 1.party_congruence
reg obj_centered party_congruence##named trump if study_2==1, r
lincom 1.party_congruence#1.named+ 1.party_congruence
	   
reg trim_obj party_congruence##named trump if study_1==1, r
lincom 1.party_congruence#1.named+ 1.party_congruence
reg trim_obj party_congruence##named trump if study_2==1, r
lincom 1.party_congruence#1.named+ 1.party_congruence

//Three way interaction tests
reg subjective party_congruence##named##low_v trump if study_1==1, r
reg subjective party_congruence##named##low_v trump if study_2==1, r

reg obj_centered party_congruence##named##low_v trump if study_1==1, r
reg obj_centered party_congruence##named##low_v trump if study_2==1, r

**STORE REGRESSIONS TO OUTPUT FOR APPENDIX
label var named "President Named"
label var party_congruence "Party Congruent"
label var low_v "Low Volatility"

reg subjective party_congruence##named trump if study_1==1, r
eststo s1_pooled_sub, title("Study 1")
reg subjective party_congruence##named trump if study_2==1, r
eststo s2_pooled_sub, title("Study 2")

reg obj_centered party_congruence##named trump if study_1==1, r
eststo s1_pooled_obj, title("Study 1")
reg obj_centered party_congruence##named trump if study_2==1, r
eststo s2_pooled_obj, title("Study 2")

reg subjective party_congruence##named##low_v trump if study_1==1, r
eststo s1_pooled_subX, title("Study 1")
reg subjective party_congruence##named##low_v trump if study_2==1, r
eststo s2_pooled_subX, title("Study 2")

reg obj_centered party_congruence##named##low_v trump if study_1==1, r
eststo s1_pooled_objX, title("Study 1")
reg obj_centered party_congruence##named##low_v trump if study_2==1, r
eststo s2_pooled_objX, title("Study 2")

** FALSE POSITIVE FX? (OBJECTIVE, STUDY 2)
reg trim_obj party_congruence##named trump if study_1==1, r
eststo s1_trim, title("Study 1")
reg trim_obj party_congruence##named trump if study_2==1, r
eststo s2_trim, title("Study 2")
reg trim_obj party_congruence##named trump if study_2==1 & objective>=100, r
eststo s2_trim100, title("Study 2 (exclude if $<$ 100)")
esttab s1_trim s2_trim s2_trim100 using "TA5_trimmed.tex", replace order(* trump) nogaps compress booktabs wrap varwidth(60) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) longtable nonotes label interaction(" $\times$ ") nodepvars nobaselevels fragment

** TREATMENT CONDITION--> NON NUMERIC RESPONSE? No.
gen non_numeric = 0
replace non_numeric = 1 if objective==.
reg non_numeric party_congruence##named trump if study_2==1
reg non_numeric party_congruence##named##low_v trump if study_2==1

**FIGURES
coefplot (subjective_nname_s1, rename((1) = "Unnamed" ) \ subjective_name_s1, rename((1) = "Named") msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 1))  (subjective_nname_s2, rename((1) = "Unnamed" ) \ subjective_name_s2, rename((1) = "Named") msymbol(T) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 2)) , legend(col(2) span region(lcolor(white) color(none)) size(small) ) level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Subjective Assessments",  size(medsmall)) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-1(.5)2) xline(0, lc(black) lw(thin) )  yscale(lw(none)) 
graph export "F1_subjective_dow.eps", as(eps) replace

coefplot (obj_centered_nname_s1, rename((1) = "Unnamed" ) \ obj_centered_name_s1, rename((1) = "Named") msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 1))  (obj_centered_nname_s2, rename((1) = "Unnamed" ) \ obj_centered_name_s2, rename((1) = "Named") msymbol(T) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 2)) , legend(col(2) span region(lcolor(white) color(none)) size(small) )  level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Objective Perceptions Assessments",  size(medsmall))  graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-1000(500)3000) xline(0, lc(black) lw(thin) )  yscale(lw(none)) 
graph export "F2_obj_centered_dow.eps", as(eps) replace

coefplot (trim_obj_nname_s1, rename((1) = "Unnamed" ) \ trim_obj_name_s1, rename((1) = "Named") msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 1))  (trim_obj_nname_s2, rename((1) = "Unnamed" ) \ trim_obj_name_s2, rename((1) = "Named") msymbol(T) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 2)) , legend(col(2) span region(lcolor(white) color(none)) size(small) )  level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Objective Perceptions Assessments",  size(medsmall)) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-1000(500)3000) xline(0, lc(black) lw(thin) )  yscale(lw(none)) 
graph export "FA1_trim_obj_dow.eps", as(eps) replace

coefplot (subjective_nname_lv_s1, rename((1) = "Unnamed: Low Volatility" ) \ subjective_nname_hv_s1, rename((1) = "Unnamed: High Volatility" ) \ subjective_name_lv_s1, rename((1) = "Named: Low Volatility") \ subjective_name_hv_s1, rename((1) = "Named: High Volatility") msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 1))  (subjective_nname_lv_s2, rename((1) = "Unnamed: Low Volatility" ) \ subjective_nname_hv_s2, rename((1) = "Unnamed: High Volatility" ) \ subjective_name_lv_s2, rename((1) = "Named: Low Volatility") \ subjective_name_hv_s2, rename((1) = "Named: High Volatility") msymbol(T) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 2)) , legend(col(2) span region(lcolor(white) color(none)) size(small) ) level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Subjective Assessments",  size(medsmall)) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-1(.5)2) xline(0, lc(black) lw(thin) )  yscale(lw(none)) 
graph export "FA2_subjective_vol.eps", as(eps) replace


coefplot (obj_centered_nname_lv_s1, rename((1) = "Unnamed: Low Volatility" ) \ obj_centered_nname_hv_s1, rename((1) = "Unnamed: High Volatility" ) \ obj_centered_name_lv_s1, rename((1) = "Named: Low Volatility") \ obj_centered_name_hv_s1, rename((1) = "Named: High Volatility") msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 1))  (obj_centered_nname_lv_s2, rename((1) = "Unnamed: Low Volatility" ) \ obj_centered_nname_hv_s2, rename((1) = "Unnamed: High Volatility" ) \ obj_centered_name_lv_s2, rename((1) = "Named: Low Volatility") \ obj_centered_name_hv_s2, rename((1) = "Named: High Volatility") msymbol(T) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Study 2)) , legend(col(2) span region(lcolor(white) color(none)) size(small) ) level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Subjective Assessments",  size(medsmall))  graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-2000(1000)3000) xline(0, lc(black) lw(thin) )  yscale(lw(none)) 
graph export "FA3_obj_centered_vol.eps", as(eps) replace




********STUDY 3***************
use "..\study_3.dta", clear

***SUMMARY STATS
estpost summarize female r_white r_black r_hispanic r_other age educ income_nomiss incomemis democrat republican partyid  
eststo study_3, title("Study 3 (Manufacturing)")
esttab study_1 study_2 study_3 using "TA1_descriptives.tex", cells(mean(fmt(2))) replace nogaps booktabs wrap varwidth(40) b(%9.3) se(%9.3f) star(+ 0.10 * 0.05 ** .01) nonotes nodepvars label


**REGRESSIONS FOR FIGURES
recode named (1=0) (0=1), gen(unnamed)

foreach i in subjective obj bias{
reg `i' party_congruence##named trump, r
lincomest 1.party_congruence 
est store `i'_nname

reg `i' party_congruence##unnamed trump, r
lincomest 1.party_congruence 
est store `i'_name

//Now doing regressions by media fit
reg `i' party_congruence##named trump if media_congruence==0 & media_incongruence==0, r
lincomest 1.party_congruence 
est store `i'_nname_no_media

reg `i' party_congruence##named trump if media_congruence==1, r
lincomest 1.party_congruence 
est store `i'_nname_med_cong

reg `i' party_congruence##named trump if media_incongruence==1, r
lincomest 1.party_congruence 
est store `i'_nname_med_incong

reg `i' party_congruence##unnamed trump if media_congruence==0 & media_incongruence==0, r
lincomest 1.party_congruence 
est store `i'_name_no_media

reg `i' party_congruence##unnamed trump if media_congruence==1, r
lincomest 1.party_congruence 
est store `i'_name_med_cong

reg `i' party_congruence##unnamed trump if media_incongruence==1, r
lincomest 1.party_congruence 
est store `i'_name_med_incong
}

coefplot (subjective_nname, rename((1) = "Unnamed" ) \ subjective_name, rename((1) = "Named" ) msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Pooled)) (subjective_nname_no_media, rename((1) = "Unnamed" ) \ subjective_name_no_media, rename((1) = "Named" ) msymbol(S) connect(none) msize(medium) mcolor(gs8) ciopts(lcolor(gs8) lwidth(thin)) label(No Media Cue)) (subjective_nname_med_cong, rename((1) = "Unnamed" ) \ subjective_name_med_cong, rename((1) = "Named" ) msymbol(Oh) connect(none) msize(medium) mcolor(gs8) ciopts(lcolor(gs8) lwidth(thin)) label(Friendly Media)) (subjective_nname_med_incong, rename((1) = "Unnamed" ) \ subjective_name_med_incong, rename((1) = "Named" ) msymbol(Th) connect(none) msize(medium) mcolor(gs8) ciopts(lcolor(gs8) lwidth(thin)) label(Unfriedly Media)),  legend(col(4) span region(lcolor(white) color(none)) size(small) ) level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Subjective Assessments",  size(medsmall))  graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-1 0 1 2 3) yline(4.5, lc(gs8) lw(thin) lpattern(dash) )  xline(0, lc(black) lw(thin) ) xscale(lw(none)) 
graph export "F3_subjective_media_s3.eps", as(eps) replace

coefplot (obj_nname, rename((1) = "Unnamed" ) \ obj_name, rename((1) = "Named" ) msymbol(S) connect(none) msize(medium) mcolor(black) ciopts(lcolor(black) lwidth(thin)) label(Pooled)) (obj_nname_no_media, rename((1) = "Unnamed" ) \ obj_name_no_media, rename((1) = "Named" ) msymbol(S) connect(none) msize(medium) mcolor(gs8) ciopts(lcolor(gs8) lwidth(thin)) label(No Media Cue)) (obj_nname_med_cong, rename((1) = "Unnamed" ) \ obj_name_med_cong, rename((1) = "Named" ) msymbol(Oh) connect(none) msize(medium) mcolor(gs8) ciopts(lcolor(gs8) lwidth(thin)) label(Friendly Media)) (obj_nname_med_incong, rename((1) = "Unnamed" ) \ obj_name_med_incong, rename((1) = "Named" ) msymbol(Th) connect(none) msize(medium) mcolor(gs8) ciopts(lcolor(gs8) lwidth(thin)) label(Unfriedly Media)),  legend(col(4) span region(lcolor(white) color(none)) size(small) ) level(95) coeflabels(,wrap(30)) title("",  size(med)) xtitle("Effect of Party Congruence on Objective Perceptions",  size(medsmall))  graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) yline(4.5, lc(gs8) lw(thin) lpattern(dash) )  xline(0, lc(black) lw(thin) ) xscale(lw(none)) 
graph export "F4_obj_media_s3.eps", as(eps) replace

**OUTPUT REGRESSIONS
label var named "President Named"
label var party_congruence "Party Congruent"
*blank indicator so label outputs properly with esttab command below
gen low_v=0
label var low_v "Low Volatility"

reg subjective party_congruence##named trump, r
eststo s3_pooled_sub, title("Study 3")

reg subjective party_congruence##named##(media_congruence media_incongruence) trump , r
eststo s3_pooled_subX, title("Study 3")

replace obj=obj/1000
reg obj party_congruence##named trump, r
eststo s3_pooled_obj, title("Study 3")

reg obj party_congruence##named##(media_congruence media_incongruence) trump , r
eststo s3_pooled_objX, title("Study 3")

esttab s1_pooled_sub s1_pooled_subX s2_pooled_sub s2_pooled_subX s3_pooled_sub s3_pooled_subX  using "TA3_subjective.tex", replace order(* trump) nogaps compress booktabs wrap varwidth(65) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) longtable nonotes label interaction(" $\times$ ") nodepvars nobaselevels fragment
esttab s1_pooled_obj s1_pooled_objX s2_pooled_obj s2_pooled_objX s3_pooled_obj s3_pooled_objX  using "TA4_objective.tex", replace order(* trump) nogaps compress booktabs wrap varwidth(45) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) longtable nonotes label interaction(" $\times$ ") nodepvars nobaselevels fragment
